package io.renren.wh.bank.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.wh.bank.entity.BankEntity;
import io.renren.wh.bank.service.BankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping("wh/ware/bank")
@Api(value = "银行信息", tags = {"银行信息相关接口"})
public class BankController {
    @Autowired
    private BankService bankService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("wh:bank:list")
    @ApiOperation(value = "获取银行信息列表", notes = "获取银行信息列表", httpMethod = "GET")
    public R list(
            @ApiParam(name = "params", value = "查询条件", required = false)
            @RequestParam Map<String, Object> params){
        PageUtils page = bankService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value = "根据id查询银行信息", notes = "根据id查询银行信息", httpMethod = "GET")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("wh:bank:info")
    public R info(@PathVariable("id") Integer id){
		BankEntity bank = bankService.getById(id);

        return R.ok().put("bank", bank);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "添加银行信息", notes = "添加银行信息", httpMethod = "POST")
    @RequestMapping("/save")
    @RequiresPermissions("wh:bank:save")
    public R save(@RequestBody BankEntity bank){
		bankService.save(bank);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改银行信息", notes = "修改银行信息", httpMethod = "PUT")
    @RequestMapping("/update")
    @RequiresPermissions("wh:bank:update")
    public R update(@RequestBody BankEntity bank){
		bankService.updateById(bank);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "根据id删除银行信息", notes = "根据id删除银行信息", httpMethod = "DELETE")
    @RequestMapping("/delete")
    @RequiresPermissions("wh:bank:delete")
    public R delete(@RequestBody Integer[] ids){
		bankService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
